Page({

  /**
   * 页面的初始数据
   */
  data: {
    users: [],
    page: {next_page: 1},
    id: null,
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    console.log(options)
    var ops_type = ''
    if (options.type != "null" && options.type != "undefined") {
      ops_type = options.type
    }
    this.setData({
      id: options.id
    })
    this.sendRequest(ops_type)
  },

  
  onReachBottom(e) {
    this.sendRequest('')
  },

  sendRequest(arg) {
    var that = this
    var page = this.data.page.next_page
    var title = "成员列表"
    if(arg && arg != "null" && arg != "undefined") {
      title = arg
    }
    if (page === null) {
      return false
    }
    wx.request({
      url: "https://kaifan.chuanggj.com/wechat/subjects/" + that.data.id + "/users?type=" + arg + "&page=" + page,
      header: {
        "Authorization": wx.getStorageSync("token")
      },
      success(res) {
        var data = res.data.users
        wx.setNavigationBarTitle({
          title: title + "(" + res.data.page.total_count + ")",
        })
        that.setData({
          users: that.data.users.concat(data),
          page: res.data.page
        })
      }
    })
  }
})